<%--
  Created by IntelliJ IDEA.
  User: huadongyu
  Date: 2025/10/13
  Time: 20:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>评论审核</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/back-index.css" />
    <script src="${pageContext.request.contextPath}/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap-paginator.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap-mypaginator.js"></script>

    <script type="text/javascript" >
        $(function(){
            // 设置参数默认值
            $("#nickname").val("${commentParam.nickname}")
            $("#context").val("${commentParam.context}")
            $("#createStartDate").val("${commentParam.createStartDate}");
            $("#createEndDate").val("${commentParam.createEndDate}");
            if("${commentParam.status}" !=''){
                $("#status").val("${commentParam.status}");
            }


            // 显示隐藏查询列表
            $('#show-user-search').click(function() {
                $('#show-user-search').hide();
                $('#upp-user-search').show();
                $('.showusersearch').slideDown(500);
            });
            $('#upp-user-search').click(function() {
                $('#show-user-search').show();
                $('#upp-user-search').hide();
                $('.showusersearch').slideUp(500);
            });

// 查询点击事件
            $("#doSearch").click(function() {
                // 重置为第一页
                $("#pageNo").val(1);
                $("#searchForm").submit();
            });
            $("#commentPageHelper").bootstrapPaginator({
                bootstrapMajorVersion: 3,
                currentPage: "${commentPage.pageNum== 0 ? 1 : commentPage.pageNum}",
                totalPages: "${commentPage.pages== 0 ? 1 : commentPage.pages}",
                size: "normal",
                alignment: "center",
                onPageClicked: function (event, originalEvent, type, page) {
                    $("#pageNo").val(page);
                    $("#searchForm").submit();
                }
            })


            //     启用与禁用
            $("input[name='modifyStatus']").click(function () {
                $.ajax({
                    type: "post",
                    url: "${pageContext.request.contextPath}/comment/modifyStatus",
                    data: {
                        "id": $(this).attr("data-id"),
                        "status": $(this).attr("data-status")
                    },
                    dataType: "json",
                    success: function (result) {
                        if (result.responseCode == "2001") {
                            location.href = "${pageContext.request.contextPath}/comment/findByParams?pageNo=${commentPage.pageNum == 0 ? 1 : commentPage.pageNum}";
                        } else {
                            $("#errorMsg").html(result.message);
                        }
                    }
                })
            });

            //按钮的超链接设置函数
            //      myoptions.pageUrl = function(type, page, current) {
            //          return "${pageContext.request.contextPath }/findAll.do?pageNo="
            //                  + page;
            //      };
            //分页回调函数,点击按钮事件
            myoptions.onPageClicked = function(event, originalEvent, type, page) {
                //ajax回调接收数据成功时再重新初始化分页按钮
                console.log("pageNo=", page);
//                 location.href= ".../pageNo=" + page;
            };

            //分页,在bootstrap-mypaginator.js中
            // myPaginatorFun("myPages", 1, 9);
        });
    </script>
</head>

<body>
<div class="panel panel-default" id="userSet">
    <div class="panel-heading">
        <h3 class="panel-title">评论审核</h3>
    </div>
    <div>
        <input type="button" value="查询" class="btn btn-success" id="doSearch" style="margin: 5px 5px 5px 15px;" />
        <input type="button" class="btn btn-primary" id="show-user-search" value="展开搜索" />
        <input type="button" value="收起搜索" class="btn btn-primary" id="upp-user-search" style="display: none;" />
    </div>

    <div class="panel-body">
        <div class="showusersearch" style="display: none;">
<%--            表单提交--%>
            <form id="searchForm" action="${pageContext.request.contextPath}/comment/findByParams" class="form-horizontal">
                <div class="form-group">
                    <div class="form-group col-xs-6">
                        <input type="hidden" id="pageNo" name="pageNo">
                        <label for="nickname" class="col-xs-3 control-label">用户名：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="nickname" name="nickname" placeholder="请输入用户名" />
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label for="context" class="col-xs-3 control-label">评论内容：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="context" name="context" placeholder="请输入评论内容" />
                        </div>
                    </div>
                </div>
                 <div class="form-group">
                    <div class="form-group col-xs-6">
                        <label for="status" class="col-xs-3 control-label">状态：</label>
                        <div class="col-xs-8">
                            <select class="form-control" id="status" name="status" >
                                <option value="-1" >全部</option>
                                <option value="2" >待审核</option>
                                <option value="0" >通过</option>
                                <option value="1" >禁用</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="form-group col-xs-6">
                        <label class="col-xs-3 control-label">开始日期：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="createStartDate" name="createStartDate" placeholder="请输入评论开始时间:2017-10-10" />
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label class="col-xs-3 control-label">结束日期：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="createEndDate" name="createEndDate" placeholder="请输入评论结束时间:2017-10-12" />
                        </div>
                    </div>
                </div>

            </form>
        </div>

        <div class="show-list">
            <table class="table table-bordered table-hover" style='text-align: center;'>
                <thead>
                <tr class="text-danger">
                    <th class="text-center">编号</th>
                    <th class="text-center">评论内容</th>
                    <th class="text-center">用户名</th>
                    <th class="text-center">评论时间</th>
                    <th class="text-center">赞</th>
                    <th class="text-center">状态</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody id="tb">
                <c:forEach items="${commentPage.list}" var="comment">
                <tr>
                    <td>${comment.id}</td>
                    <td>${comment.context}</td>
                    <td>${comment.user.nickname}</td>
                    <td>${comment.createDate}</td>
                    <td>${comment.likeCount}</td>
                    <c:if test="${comment.status==2}">
                    <td>待审核</td>
                    </c:if>
                    <c:if test="${comment.status==0}">
                        <td>通过</td>
                    </c:if>
                    <c:if test="${comment.status==1}">
                        <td>禁用</td>
                    </c:if>
                    <td class="text-center">
<%--                        <c:if test="${comment.status==2}">--%>
                        <input type="button" name="modifyStatus" data-id="${comment.id}" data-status="0" class="btn btn-success btn-sm" value="通过" />
                        <input type="button" name="modifyStatus" data-id="${comment.id}" data-status="1" class="btn btn-danger btn-sm" value="禁用" />
<%--                        </c:if>--%>
                    </td>
                </tr>
                </c:forEach>
                </tbody>
            </table>
            <ul id="commentPageHelper"></ul>
        </div>

        <!-- 分页 -->
<%--        <div style="text-align: center;" >--%>
<%--            <ul id="myPages" ></ul>--%>
<%--        </div>--%>

    </div>
</div>
</body>

</html>
